<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <meta name="Author" content="Ward Cunningham">
   <meta name="GENERATOR" content="Mozilla/4.5 [en]C-CCK-MCD compaq  (Win98; U) [Netscape]">
   <title>Arithmetic</title>
</head>
<body>

<h1>
Integer Arithmetic</h1>

<p>The computer relies on arithmetic. Here we test a variety of arithmetic
operations expressed as 32 bit two's complement binary numbers (Java's
int).
<br>&nbsp;
<table BORDER COLS=6 CELLSPACING=0 CELLPADDING=3 >
<tr>
<td COLSPAN="6">eg.ArithmeticFixture</td>
</tr>

<tr>
<td>x</td>

<td>y</td>

<td>+</td>

<td>-</td>

<td>*</td>

<td>/</td>
</tr>

<tr>
<td>0</td>

<td>0</td>

<td bgcolor="#cfffcf">0</td>

<td bgcolor="#cfffcf">0</td>

<td bgcolor="#cfffcf">0</td>

<td bgcolor="#ffffcf">0<hr><pre>java.lang.ArithmeticException: / by zero<br />	at eg.ArithmeticFixture.doCell(Unknown Source)<br />	at fit.Fixture.doCells(Unknown Source)<br />	at fit.Fixture.doRow(Unknown Source)<br />	at fit.Fixture.doRows(Unknown Source)<br />	at eg.ArithmeticFixture.doRows(Unknown Source)<br />	at fit.Fixture.doTable(Unknown Source)<br />	at fit.Fixture.interpretTables(Unknown Source)<br />	at fit.Fixture.doTables(Unknown Source)<br />	at fit.FileRunner.process(Unknown Source)<br />	at fit.FileRunner.run(Unknown Source)<br />	at fit.FileRunner.main(Unknown Source)<br /></pre></td>
</tr>


<tr>
<td>1</td>

<td>2</td>

<td bgcolor="#cfffcf">3</td>

<td bgcolor="#cfffcf">-1</td>

<td bgcolor="#cfffcf">2</td>

<td bgcolor="#ffffcf">0.5<hr><pre>java.lang.NumberFormatException: For input string: "0.5"<br />	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)<br />	at java.lang.Long.parseLong(Long.java:403)<br />	at java.lang.Long.parseLong(Long.java:452)<br />	at fit.PrimitiveFixture.parseLong(Unknown Source)<br />	at fit.PrimitiveFixture.check(Unknown Source)<br />	at eg.ArithmeticFixture.doCell(Unknown Source)<br />	at fit.Fixture.doCells(Unknown Source)<br />	at fit.Fixture.doRow(Unknown Source)<br />	at fit.Fixture.doRows(Unknown Source)<br />	at eg.ArithmeticFixture.doRows(Unknown Source)<br />	at fit.Fixture.doTable(Unknown Source)<br />	at fit.Fixture.interpretTables(Unknown Source)<br />	at fit.Fixture.doTables(Unknown Source)<br />	at fit.FileRunner.process(Unknown Source)<br />	at fit.FileRunner.run(Unknown Source)<br />	at fit.FileRunner.main(Unknown Source)<br /></pre></td>
</tr>

<tr>
<td>1</td>

<td>-1</td>

<td bgcolor="#cfffcf">0</td>

<td bgcolor="#cfffcf">2</td>

<td bgcolor="#cfffcf">-1</td>

<td bgcolor="#cfffcf">-1</td>
</tr>

<tr>
<td>10000</td>

<td>10000</td>

<td bgcolor="#cfffcf">20000</td>

<td bgcolor="#cfffcf">0</td>

<td bgcolor="#cfffcf">100000000</td>

<td bgcolor="#cfffcf">1</td>
</tr>

<tr>
<td>100000</td>

<td>100000</td>

<td bgcolor="#cfffcf">200000</td>

<td bgcolor="#cfffcf">0</td>

<td bgcolor="#ffcfcf">10000000000 <font size=-1 color="#c08080"><i>expected</i></font><hr>1410065408 <font size=-1 color="#c08080"><i>actual</i></font></td>

<td bgcolor="#cfffcf">1</td>
</tr>

<tr>
<td>1000000</td>

<td>1000000</td>

<td bgcolor="#cfffcf">2000000</td>

<td bgcolor="#cfffcf">0</td>

<td bgcolor="#ffcfcf">1000000000000 <font size=-1 color="#c08080"><i>expected</i></font><hr>-727379968 <font size=-1 color="#c08080"><i>actual</i></font></td>

<td bgcolor="#cfffcf">1</td>
</tr>
</table>

<br><br>
Now we try something similar using automatic type conversion offered by ColumnFixtures (BFL1).
<br><br>

<table BORDER CELLSPACING=0 CELLPADDING=3>
    <tr>
        <td colspan=5>eg.ArithmeticColumnFixture</td>
    </tr>
    <tr>
        <td>x</td>
        <td>y</td>
        <td>plus()</td>
        <td>times()</td>
        <td>divide()</td>
        <td>floating()</td>
    </tr>
    <tr>
        <td>2</td>
        <td>3</td>
        <td bgcolor="#cfffcf">5</td>
        <td bgcolor="#cfffcf">6</td>
        <td bgcolor="#cfffcf">0</td>
        <td bgcolor="#cfffcf">0.6666667</td>
    </tr>
    <tr>
        <td>0</td>
        <td>0</td>
        <td bgcolor="#cfffcf">0</td>
        <td bgcolor="#cfffcf">0</td>
        <td bgcolor="#cfffcf">error</td>
        <td bgcolor="#ffcfcf">error <font size=-1 color="#c08080"><i>expected</i></font><hr>NaN <font size=-1 color="#c08080"><i>actual</i></font></td>
    </tr>
    <tr>
        <td>0</td>
        <td>0</td>
        <td bgcolor="#cfffcf">0</td>
        <td bgcolor="#cfffcf">0</td>
        <td> <font color="#808080">error</font></td>
        <td> <font color="#808080">NaN</font></td>
    </tr>
    <tr>
        <td>200</td>
        <td>300</td>
        <td bgcolor="#cfffcf">500</td>
        <td bgcolor="#cfffcf">60000</td>
        <td bgcolor="#cfffcf">0</td>
        <td bgcolor="#cfffcf">0.6666667</td>
    </tr>
    <tr>
        <td>2</td>
        <td>3</td>
        <td bgcolor="#ffcfcf">10 <font size=-1 color="#c08080"><i>expected</i></font><hr>5 <font size=-1 color="#c08080"><i>actual</i></font></td>
        <td bgcolor="#ffcfcf">10 <font size=-1 color="#c08080"><i>expected</i></font><hr>6 <font size=-1 color="#c08080"><i>actual</i></font></td>
        <td bgcolor="#ffcfcf">10 <font size=-1 color="#c08080"><i>expected</i></font><hr>0 <font size=-1 color="#c08080"><i>actual</i></font></td>
    </tr>
    <tr>
        <td>200</td>
        <td>3</td>
        <td bgcolor="#ffcfcf">5 <font size=-1 color="#c08080"><i>expected</i></font><hr>203 <font size=-1 color="#c08080"><i>actual</i></font></td>
        <td bgcolor="#ffcfcf">6 <font size=-1 color="#c08080"><i>expected</i></font><hr>600 <font size=-1 color="#c08080"><i>actual</i></font></td>
        <td bgcolor="#ffcfcf">0 <font size=-1 color="#c08080"><i>expected</i></font><hr>66 <font size=-1 color="#c08080"><i>actual</i></font></td>
        <td bgcolor="#ffcfcf">0.6666667 <font size=-1 color="#c08080"><i>expected</i></font><hr>66.666664 <font size=-1 color="#c08080"><i>actual</i></font></td>
    </tr>
    <tr>
        <td>2</td>
        <td>-3</td>
        <td bgcolor="#cfffcf">-1</td>
        <td bgcolor="#cfffcf">-6</td>
        <td bgcolor="#cfffcf">-0</td>
        <td bgcolor="#cfffcf">-0.6666667</td>
    </tr>
</table>

<br><br>


<table BORDER CELLSPACING=0 CELLPADDING=3>
<tr>
<td COLSPAN="2">fit.Summary</td>
</tr>
<tr>
<td> <font color="#808080">counts</font></td>
<td bgcolor="#ffcfcf">37 right, 10 wrong, 0 ignored, 2 exceptions</td></tr>
<tr>
<td> <font color="#808080">input file</font></td>
<td> <font color="#808080">C:\projects\fit\imp\java\..\..\examples\arithmetic.html</font></td></tr>
<tr>
<td> <font color="#808080">input update</font></td>
<td> <font color="#808080">Tue Sep 16 17:43:29 PDT 2003</font></td></tr>
<tr>
<td> <font color="#808080">output file</font></td>
<td> <font color="#808080">C:\projects\fit\imp\java\output\examples\arithmetic.html</font></td></tr>
<tr>
<td> <font color="#808080">run date</font></td>
<td> <font color="#808080">Thu Apr 07 23:25:18 PDT 2005</font></td></tr>
<tr>
<td> <font color="#808080">run elapsed time</font></td>
<td> <font color="#808080">0:00.11</font></td></tr></table>



<p>Document prepaired by Ward Cunningham
<br>First Version July 11, 2002
<br>Last Update August 17, 2002
</body>
</html>
